package com.zhaoyd.uaademo.config.security.handler;

import com.zhaoyd.uaademo.core.BaseLogger;
import com.zhaoyd.uaademo.core.ResultData;
import com.zhaoyd.uaademo.util.JsonBeanConvertUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
public class LoginSuccessHandler extends BaseLogger implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        log.info("login success");
        httpServletResponse.setContentType("application/json;charset=utf-8");
        PrintWriter writer = httpServletResponse.getWriter();
        ResultData resultData = ResultData.success("登录成功!");
        writer.write(JsonBeanConvertUtils.beanToJson(resultData));
        writer.flush();
        writer.close();
    }
}
